import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SaoWidget extends StatefulWidget {
  const SaoWidget({super.key});

  @override
  State<SaoWidget> createState() => _SaoWidgetState();
}

class _SaoWidgetState extends State<SaoWidget>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late List<String> _frames;
  late int _frameCount;
  @override
  void initState() {
    super.initState();
    // Initialize the frames
    _frames =
        List.generate(31, (index) => 'assets/images/other/${index + 1}.png');
    _frameCount = _frames.length;

    _controller = AnimationController(
      duration: Duration(
          seconds: _frameCount ~/ 12), // Total duration for the animation
      vsync: this,
    )..repeat();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    // Place your MediaQuery or inherited widget dependent code here if needed
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _controller,
      builder: (context, child) {
        int frameIndex =
            (_controller.value * _frameCount).floor() % _frameCount;
        return Image.asset(
          _frames[frameIndex],
          width: 500.sp,
          height: 500.sp,
        );
      },
    );
  }
}
